package com.uff.hmstpa.model.domain;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;

import com.uff.hmstpa.model.decorator.IAppointment;

public class Appointment implements IAppointment {

	private Doctor doctor;
	private Patient patient;
	private DateTime time;
	private double price = -1;

	private IAppointment appointment;

	public Appointment() {
	}

	public Appointment(IAppointment appointment, Doctor doctor, Patient patient) {
		this.appointment = appointment;
		this.doctor = doctor;
		this.patient = patient;
	}

	public Appointment(Doctor doctor, Patient patient) {
		this.doctor = doctor;
		this.patient = patient;
	}

	public Patient getPatient() {
		return patient;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}

	public Doctor getDoctor() {
		return doctor;
	}

	public void setDoctor(Doctor doctor) {
		this.doctor = doctor;
	}


	public DateTime getTime() {
		return time;
	}

	public void setTime(DateTime time) {
		this.time = time;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public double getPrice() {
		if(price != -1) {
			return this.price;
		} else {
			return appointment.getPrice();
		}
	}

	public void setAppointment(IAppointment appointment) {
		this.appointment = appointment;
	}

	@Override
	public String toString() {
		DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral("-").appendMonthOfYear(2).appendLiteral("-")
				.appendDayOfMonth(2).appendLiteral(" ").appendHourOfDay(2).appendLiteral(":").appendMinuteOfHour(2).toFormatter();

		return time.toString(dtf) + " - " + patient.getName() + " (R$ " + this.getPrice() + ")";
	}


}
